<template>
  <div>
    <article class="innerPage bookList">
      <header class="breadcrumb">
        <x-breadcrumb :path="$route.path" :title="$route.meta.breadcrumb" :startIndex="$route.meta.startIndex">
        </x-breadcrumb>
      </header>


      <div class="decorate"></div>
      <section class="graphical2">
        <section class="graphical">
          <SearchCondition :formItemList="formItemList" :emitSearch="emitSearch" :resetSearch="resetSearch"
            @search="search" ref="mychild" />
        </section>

        <div>
          <el-table :data="tableData" class="tableStyle" :header-cell-style="$headerCellStyle" :border="$isborder"
            size="mini" ref="elTable" stripe>
            <el-table-column prop="key" label="序号" label-class-name="indexColumn" align="center" fixed="left"
              :width="$widtha">
            </el-table-column>

            <el-table-column label="标题" :min-width="$widthb" align="left" prop="title" show-overflow-tooltip>
            </el-table-column>

            <el-table-column label="添加时间" :min-width="$widthb" align="left" prop="create_time" show-overflow-tooltip>
            </el-table-column>

            <el-table-column label="操作" fixed="right" :header-align="$heaerOpt" :width="$widthb">
              <template slot-scope="scope">
                <div class="btnFrom-box">
                  <div v-alive class="details-box" @click="pageTurn('/dataStatistics/detail',{id:scope.row.id})">
                    查看
                  </div>
                  <div v-alive @click="remove(scope.row.id)" class="delete-box">
                    <span></span> 删除
                  </div>
                </div>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </section>
      <footer class="pagination">
        <div>
          <el-pagination background prev-text="上一页" next-text="下一页" layout="prev, pager, next, jumper"
            :total="listTotal"
            :page-size="10" @current-change="handleCurrentChange" :current-page.sync="currentPage1">
          </el-pagination>

        </div>
        <p>
          共
          <span>{{ listTotal || 0 }}</span>
          数据
        </p>
      </footer>
    </article>

    <div>
      <Ddlmoadl ref="isdel" @deletesuccess="deletesuccess"></Ddlmoadl>
      <Isaudit ref="audit" @showAudit="showAudit"></Isaudit>
    </div>
  </div>
</template>

<script>
import Ddlmoadl from "@/components/Deletebtn/Deletetk.vue";
// import Changcode from "@/components/addDialog/index.vue";
import Isaudit from "@/components/agreeDialog2/index.vue";
// import Ispwd from "./components/index.vue";
export default {
  name: "AdminIndex",
  components: {
    Ddlmoadl,
    Isaudit,
  },
  data() {
    return {
      formItemList: [
        {
          label: "标题",
          type: "input",
          param: "keywords",
        },
      ],
      searchList: {
      },
      emitSearch: false,
      resetSearch: true,
      tableData: [],
      page: 1,
      listTotal: 0,
      currentPage1: 1,
      dialogVisible: false, //详情框
      particularsdata: {},
      deldialog: false, // 删框
      delid: "",
      isid: "",
      istype: "",
      typeid: "",
      copyType: "",
      idindex: "",
      is_super_admin: "false",
    };
  },

  mounted() { },
  activated() {
    if (this.$route.params.action === "refresh") {
      this.page = 1;
      this.listTotal = 0;
      this.currentPage1 = 1;
      this.tableData = [];
    }
    this.getList();
    this.$refs?.elTable?.doLayout();
    this.setPageTabs();
  },
  computed: {
    defaultImg() {
      return 'this.src="' + require("@/assets/img2/feng_shibaiimg.png") + '"';
    },
  },
  methods: {
    //获取数据
    async getList() {
      try {
        let res = await this.request({
          url: "/admin/externalDataRecord/list",
          method: "get",
          loading: true,
          data: {
            page: this.page,
            limit: 10,
            ...this.searchList,
          },
        });
        if (res) {
          this.tableData = res.content.data;
          this.listTotal = res.content.total;
          this.currentPage1 = res.content.current_page;
        }
      } catch (err) {
        let error = err.message.split("/");
        if (error[0] == 203) {
          this.tableData = [];
          this.listTotal = 0;
        }
        this.errorHandler(err);
      }
    },


    //分页
    handleCurrentChange(val) {
      this.page = val;
      this.getList();
    },
    // 搜索条件改变时
    search(params) {
      this.searchList = params;
      this.page = 1;
      this.getList();
    },

    //删除弹框
    async remove(id) {
      this.delid = id;
      this.$refs.isdel.delshow(id);
    },
    // 弹框确认后的回调
    async deletesuccess() {
      try {
        let res = await this.request({
          url: "admin/externalDataRecord/del",
          method: "post",
          loading: true,
          data: {
            id: this.delid,
          },
        });
        if (res) {
          this.$message.success(res.msg);
          let that = this;
          setTimeout(() => {
            that.getList();
          }, 2000);
        }
      } catch (err) {
        this.errorHandler(err);
      }
    },
    // 前往页面
    toPage(path, row) {
      this.$router.push({
        path: path,
        query: {
          id: row.guid,
        },
      });
    },
  },
};
</script>

<style lang="scss" scoped>
@import "./style.scss";
</style>
